package com.review.Test;

public class MyThreadLocal {

	private static ThreadLocal<String> th = new ThreadLocal<>();



	public static void getTh() {
		System.out.println(Thread.currentThread().getName() + th.get());
	}

	public static void setTh(String str) {
		th.set(str);
	}



	public static void main(String[] args) {

		final MyThreadLocal myThreadLocal = new MyThreadLocal();
		Thread t1 = new Thread(new Runnable() {

			@Override
			public void run() {
				myThreadLocal.setTh("你好");
				myThreadLocal.getTh();
			}
		},"t1");

		Thread t2 = new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				myThreadLocal.getTh();
			}
		},"t2");

		t1.start();
		t2.start();

	}

}
